
package com.amado.springboot.springbootcms.service.impl;

import java.util.List;

import com.amado.springboot.springbootcms.domain.Depa;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.amado.springboot.springbootcms.domain.User;
import com.amado.springboot.springbootcms.mapper.UserMapper;
import com.amado.springboot.springbootcms.service.UserService;
import com.amado.springboot.springbootcms.util.RedisTemplateDriver;
import com.amado.springboot.springbootcms.vo.UserLoginVO;

/**
 * @author wangyl-910
 * @description
 * @date 2017/12/4
 * @see
 */
@Service
public class UserServiceImpl implements UserService {


    Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private RedisTemplateDriver redisTemplateDriver;
    @Autowired
    private UserMapper userMapper;
    /*private DepaMapper depaMapper;*/
    private String USER_ID = "user:id:increment:key";
/*    private String DEPA_NAME = "DEPA:DEPA_ID:increment:key";*/
    public String getUserId() {
        return "userId" + redisTemplateDriver.auomicInteger(USER_ID);
    }
  /*  public String getDepaId() {
        return "DEPA_NAME" + redisTemplateDriver.auomicInteger(DEPA_NAME);
    }*/

    @Override
    public void addUser(User user) {
        user.setUserId(getUserId());

        if(user!=null){
            if ("".equals (user.getDepaId() ) && "".equals (user.getAddress())&& "".equals (user.getName())&& "".equals (user.getPassword())&& "".equals (user.getSex())&&"".equals (user.getId ())&&"".equals (user.getUserAccount ())&&"".equals (user.getUserAccount ())) {
                logger.debug("返回值" );
            }else{
                userMapper.insertSelective(user);
            }
        }

    }



    @Override
    public void delete(List<Long> id) {
       if(id.size () != 0){
           userMapper.delete(id);
       }

    }



    @Override
    public User get(Long id) {
        User user;
        if(id != 0){
            user = userMapper.get(id);
            return user;
        }

        return null;
    }

    public User getUser(Long id) {
        User user;
        if(id != null){
             user = userMapper.get(id);
             return user;
        }

        return null;
    }

    @Override
    public void modify(User user) {
        if(user!=null){
            if ("".equals (user.getDepaId() ) && "".equals (user.getAddress())&& "".equals (user.getName())&& "".equals (user.getPassword())&& "".equals (user.getSex())&&"".equals (user.getId ())&&"".equals (user.getUserAccount ())&&"".equals (user.getUserAccount ())) {
                logger.debug("返回值" );
            }else{
                userMapper.modify(user);
            }
        }

    }

    @Override
    public User loginAndGet(UserLoginVO userLoginVO) {
        User user = userMapper.selectByUserAccount(userLoginVO.getUserAccount());
        if (user == null || !user.getPassword().equals(userLoginVO.getPassword())) {
            return null;
        }
        return user;
    }

    @Override
    public List<User> getAllUser() {
        return userMapper.queryAll();
    }



}
